package com.horse.cloud.boss.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.horse.cloud.data.access.boss.entity.ClBossArea;
import com.horse.cloud.data.access.boss.entity.ClBossUser;
import com.horse.cloud.data.access.boss.mapperInterface.ClBossAreaMapper;
import com.horse.cloud.data.access.boss.mapperInterface.ClBossUserMapper;
import com.horse.cloud.data.domain.boss.BossUserQueryBo;
import com.horse.cloud.data.domain.boss.BossUserVo;
import com.horse.cloud.framework.base.BaseService;
import com.horse.cloud.framework.base.callback.DoTransactionContent;
import com.horse.cloud.framework.general.response.Response;
import com.horse.cloud.framework.general.utils.IdWorkerUtils;
import io.micrometer.core.instrument.Meter;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : bing.Pan
 * @create : Created by intelliJ IDEA
 * @e-mail : 15923508369@163.com
 * @gmdate : 03/28/2018 14:16 星期三
 * @sidesc :
 */
@Service
public class BossUserService extends BaseService {

	@Autowired ClBossUserMapper bossUserMapper;
	@Autowired ClBossAreaMapper clBossAreaMapper;



	public Response userList(BossUserQueryBo bossUserQueryBo) {

		PageHelper.startPage(bossUserQueryBo.getPageIndex(), bossUserQueryBo.getPageSize(),bossUserQueryBo.isTotalCount());
		ClBossUser clBossUser = new ClBossUser();
		BeanUtils.copyProperties(bossUserQueryBo,clBossUser);
		PageInfo clBossUserPageInfo = new PageInfo<>(bossUserMapper.findListByT(clBossUser));

		List<BossUserVo> viewQueryList = new ArrayList<>();
		for (ClBossUser dataQuery :(List<ClBossUser>)clBossUserPageInfo.getList()) {
			BossUserVo bossUserVo = new BossUserVo();
			BeanUtils.copyProperties(dataQuery,bossUserVo);
			viewQueryList.add(bossUserVo);
		}

		clBossUserPageInfo.setList(viewQueryList);


		IdWorkerUtils idWorkerUtils = new IdWorkerUtils(31,31);

		final long[] temp = new long[1];
		 withTransaction(new DoTransactionContent() {
			@Override
			public Response execute() throws Exception {
				for(int x = 1; x < 10; x ++){
					long l = idWorkerUtils.nextId();
					ClBossUser clBossUser = new ClBossUser();
					clBossUser.setId(l);
					clBossUser.setUserNumber(String.valueOf(idWorkerUtils.nextId()));
					clBossUser.setLoginName("Gopan");
					bossUserMapper.insert(clBossUser);


					System.out.println( l + "+ " +  l % 5 +":::" + l % 9);
				temp[0] = l;

				}
				return new Response();
			}
		});


		ClBossUser clBossUser1 = bossUserMapper.selectByPrimaryKey(temp[0]);

		System.out.println(clBossUser1.toString());


		return null;


	}
}
